package MyBlog.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import MyBlog.dao.PhotoDao;
import MyBlog.entity.Photo;

@Repository("photoDao")
public class PhotoDaoImpl implements PhotoDao{

	@Autowired
	private HibernateTemplate hibernateTemplate;

	@Override
	public List<Photo> getPhotosByUserIdAndAlbumId(int albumId, int userId) {
		return (List<Photo>) hibernateTemplate.find("from Photo p where p.user.id = ? and p.album.id = ?",userId,albumId);
	}

	@Override
	public Photo getPhotoById(int id) {
		return hibernateTemplate.get(Photo.class, id);
	}

	@Override
	public void add(Photo photo) {
		hibernateTemplate.save(photo);
	}

	@Override
	public void update(Photo photo) {
		hibernateTemplate.update(photo);
	}
}
